<template>
  <div>
    <el-dialog title="相关附件" :visible.sync="show" width="600px" append-to-body @close="cancel">
      <div>
        <div class="file-item" v-for="(i, k) in dataList" :key="k">
          <div class="file-icon">
            <i class="el-icon-paperclip" />
          </div>
          <div class="file-label">
            <div class="file-name">{{ i.fileName || "-" }}</div>
            <div>
              <span>{{ i.createTime }}</span>
              <span class="file-size">{{ i.fileSize }}</span>
              <span>{{ i.createBy }}</span>
            </div>
          </div>
          <div class="file-download">
            <i class="el-icon-download" title="下载附件" @click="downloadFile(i)" />
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getWorkOrderAnnex } from "@/api/system/order";
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    row: {
      type: Object,
      default: () => { },
    },
  },
  computed: {
    show: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("input", val);
      },
    },
  },
  data() {
    return {
      baseURL: process.env.VUE_APP_BASE_API,
      dataList: [], // 评论列表
      total: 0, // 总条数
      queryForm: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  watch: {
    show(v) {
      if (v) {
        this.queryForm.pageNum = 1;
        this.getList();
      }
    },
  },
  methods: {
    // 查询操作记录列表
    getList() {
      getWorkOrderAnnex(this.row.id).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data;
        }
      });
    },
    // 下载附件
    downloadFile(i) {
      this.$download.resource(i.filePath);
    },
    // 关闭弹窗
    cancel() {
      this.show = false;
      this.dataList = [];
      this.$emit("cancel");
    },
  },
};
</script>
<style lang="scss" scoped>
.file-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 8px;
  background-color: #f6f6f6;
  transition: all 0.3s;

  &:hover {
    background-color: #f1f1f1;
  }

  .file-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    font-size: 30px;
    margin-right: 10px;
  }

  .file-label {
    flex: 1;

    .file-name {
      font-size: 16px;
      color: #333;
      line-height: 30px;
    }

    span {
      margin-right: 10px;
    }
  }

  .file-download {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    font-size: 20px;

    i:hover {
      cursor: pointer;
    }
  }
}
</style>
